-- =============================================
-- Author:		<Agurto, Jorge>
-- Modificado date: <24/10/2011>
-- =============================================

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [GOOGLECODERS].[BeneficioarioUpdate]
	@IdBeneficiario int,
	@RazonSocial varchar(255) = NULL,
	@DirCalle varchar(255) = NULL,
	@DirNro int = NULL,
	@DirPiso int = NULL,
	@DirDepto varchar(2) = NULL,
	@IdRubro int = NULL,
	@Habilitado bit = NULL
	
AS
BEGIN

	UPDATE [GOOGLECODERS].[Beneficiarios]
	SET 
	RazonSocial =	ISNULL(@RazonSocial, RazonSocial),
	DirCalle =	ISNULL(@DirCalle, DirCalle),
	DirNro =	ISNULL(@DirNro, DirNro),
	DirPiso =	ISNULL(@DirPiso, DirPiso),
	DirDepto =	ISNULL(@DirDepto, DirDepto),
	IdRubro =	ISNULL(@IdRubro, IdRubro),
	Habilitado =	ISNULL(@Habilitado, Habilitado)
	WHERE IdBeneficiario = @IdBeneficiario

	if(@Habilitado = 0)
	BEGIN
		DELETE FROM [GOOGLECODERS].[Postnet_x_Beneficiario]
		WHERE
			IdBeneficiario = @IdBeneficiario
	END
END